package com.gohome.gohomechat.presenter;

import com.gohome.gohomechat.model.LoginModel;
import com.gohome.gohomechat.model.modellistener.LoginModelInterface;
import com.gohome.gohomechat.presenter.callback.LoginCallBack;
import com.gohome.gohomechat.presenter.presenterlistener.LoginPresenterInterface;
import com.gohome.gohomechat.ui.viewlistener.LoginViewInterface;

/**
 * Created by dllo on 16/2/29.
 */
public class LoginPresenter extends BasePresenter<LoginViewInterface> implements LoginPresenterInterface {
    private LoginViewInterface loginViewInterface;
    private LoginModelInterface loginModelInterface;

    public LoginPresenter(LoginViewInterface loginViewInterface) {
        this.loginViewInterface = loginViewInterface;
        this.loginModelInterface=new LoginModel();
    }

    @Override
    public void login() {
        loginViewInterface.showDialog();
        loginModelInterface.login(loginViewInterface.userName(), loginViewInterface.userPsw(), new LoginCallBack() {
            @Override
            public void loginSuccess() {
                loginViewInterface.dismissDialog();
                loginViewInterface.toLoginSuccess();
            }

            @Override
            public void loginFailed() {
                loginViewInterface.dismissDialog();
                loginViewInterface.toLoginFailed();
            }
        });
    }

    @Override
    public void toRegisterActivit() {
        loginViewInterface.toRegisterSuccess();
    }
}
